package design_patterns.singleton;

/**
 * 静态内部类的方式 实现单例模式
 *
 * 序列化或者反序列化会破坏 单例
 *  //解决序列化和反序列化对单例的破坏
 *     private Object readResolve() {
 *         return hungarySingleton;
 *     }
 *
 * 反射 也会破坏单例模式
 * synchronized (Elvis.class) {
 *      System.out.println(" try to instance");
 *  if (flag == false) {
 *      System.out.println("first time instance");
 *      flag = !flag;
 *  } else {
 *      throw new RuntimeException("单例模式被侵犯！");
 *  }
 * }
 */
public class Singleton {

    private Singleton(){}
    private static class Inner{
        private static Singleton intence=new Singleton();
    }

    public static Singleton getIntence() {
        return Inner.intence;
    }
}
